package com.guigu.mybatis.mapper;

import com.guigu.mybatis.bean.SpHall;
import com.guigu.mybatis.bean.SpPlan;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface PlanMapper {

    @Select("select * from sp_plan where id = #{fsd}")
    @Results(id = "rm2",
    value = {
            //主键映射
            @Result(column = "id",property ="id",id = true),
            //自定义字段映射
            @Result(column = "play_time",property = "playTime"),
            @Result(column = "hid",property = "hall",
            one=@One(select = "selectHallById",fetchType = FetchType.LAZY))
    })
    public SpPlan selectById(int id);
    @Select("select * from sp_hall where id = #{hid}")
    public List<SpPlan> selectByMidAndHid(@Param("mid") int midafsf,@Param("hid") int sf);

    public SpHall selectHallById(int hid);

    @Select("  select a.id        id,\n" +
            "               a.play_time playTime,\n" +
            "               a.mid,\n" +
            "               a.hid,\n" +
            "               a.price,\n" +
            "               b.id        \"hall.id\",\n" +
            "               b.name      \"hall.name\",\n" +
            "               b.is3d      \"hall.is3d\",\n" +
            "               b.size      \"hall.size\",\n" +
            "               b.seats     \"hall.seats\"\n" +
            "        from sp_plan a\n" +
            "                 join sp_hall b on a.hid = b.id\n" +
            "        where mid = #{mid}")
    public List<SpPlan> selectByMid(int mid);

    public SpPlan selectPlanByhid(int hid);
}
